package com.pro.service.imple;

import com.pro.mapper.JsJurisdictionMapper;
import com.pro.pojo.JsClosure;
import com.pro.pojo.JsDept;
import com.pro.pojo.JsUnseal;
import com.pro.pojo.JsUser;
import com.pro.service.JsJurisdictionService;
import com.pro.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author cyj
 * @date 2022.2.27$ 15.58$
 * @content :
 */
@Service
public class JsJurisdictionServiceImple implements JsJurisdictionService {

    @Autowired(required = false)
    private JsJurisdictionMapper mapper;

    @Autowired
    private RedisCache redisCache;

    /**
     * @author cyj
     * @date 2022.2.27$ 15.59$
     * @content :获取所有的部门名称
     */
    @Override
    public List<JsDept> getDeptName() {
        List<JsDept> AlldeptList = redisCache.getCacheList("dept");
        if (!AlldeptList.isEmpty()){
            return AlldeptList;
        }
        JsDept js = new JsDept();
        js.setId(0);
        js.setParentId(-1);
        js.setDeptName("所有部门");
        List<JsDept> Alldept = mapper.getDeptName();
        Alldept.add(js);
        redisCache.setCacheList("dept",Alldept);
        return Alldept;
    }
    /**
     * @author cyj
     * @date 2022.2.27$ 19.07$
     * @content :获取所有员工信息
     */
    @Override
    public List<JsUser> getUsers(String account,String trueName,String deptName,String registerDate,Integer limit,Integer page) {
        page = (page -1 ) * limit;
        List<JsUser> jsUser = mapper.getUsers(account,trueName,deptName,registerDate,limit, page);
        return jsUser;
    }
    /**
     * @author cyj
     * @date 2022.2.27$ 19.16$
     * @content :获取所有员工信息
     */
    @Override
    public Integer countUser() {
        return mapper.countUser();
    }
    /**
     * @author cyj
     * @date 2022.3.3$ 15.27$
     * @content :更新用户状态
     */
    @Override
    public Boolean updateStatus(JsUser jsUser) {
        return mapper.updateStatus(jsUser);
    }
    /**
     * @author cyj
     * @date 2022.3.3$ 15.36$
     * @content :解封日志添加
     */
    @Override
    public Boolean insertUnseal(Integer userId,Integer type,String unsealDate) {
        return mapper.insertUnseal(userId,type,unsealDate);
    }
    /**
     * @author cyj
     * @date 2022.3.3$ 16.01$
     * @content :封禁日志添加
     */
    public Boolean addUserClosure(JsClosure jsClosure){
        return mapper.addUserClosure(jsClosure);
    }
    /**
     * @author cyj
     * @date 2022.3.4$ 9.12$
     * @content :查询某个用户的详细信息
     */
    @Override
    public JsUser getUserById(Integer id) {
        return mapper.getUserById(id);
    }
    /**
     * @author cyj
     * @date 2022.3.8$ 8.09$
     * @content :修改某个用户的信息
     */
    @Override
    public Boolean updateUser(JsUser jsUser) {
        return mapper.updateUser(jsUser);
    }
    /**
     * @author cyj
     * @date 2022.3.8$ 13.42$
     * @content :查询用户所拥有的权限
     */
    @Override
    public List<JsUser> getUserPower(Integer userId) {
        return mapper.getUserPower(userId);
    }
    /**
     * @author cyj
     * @date 2022.3.9$ 8.53$
     * @content :添加用户所拥有的权限
     */
    @Override
    public Boolean addUserGrade(JsUser user) {
        return mapper.addUserGrade(user);
    }
    /**
     * @author cyj
     * @date 2022.3.9$ 9.25$
     * @content :添加用户所拥有的权限
     */
    @Override
    public  Boolean delUserGrade(JsUser user){
        return  mapper.delUserGrade(user);
    }
    /**
     * @author cyj
     * @date 2022.3.9$ 14.09$
     * @content :添加一位用户
     */
    @Override
    public Boolean addUser(JsUser user) {
        return mapper.addUser(user);
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 8.50$
     * @content :查看解封日志
     */
    @Override
    public List<JsUnseal> getUnsealingLog(String account,String deptName,String unsealDate,Integer limit,Integer page) {
        return mapper.getUnsealingLog(account,deptName,unsealDate,limit,page);
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 8.56$
     * @content :解封日志计数
     */
    @Override
    public Integer countUnsealingLog() {
        return mapper.countUnsealingLog();
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 14.28$
     * @content :获取部门信息
     */
    @Override
    public List<JsDept> getJsDeptList(String deptName, String trueName, String createDate, String status, Integer limit, Integer page) {
        page = (page-1) * limit;
        List<JsDept> jsDeptList = mapper.getJsDeptList(deptName,trueName,createDate,status,limit,page);
        return jsDeptList;
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 14.35$
     * @content :对部门进行计数
     */
    @Override
    public Integer countJsDeptList() {
        return mapper.countJsDeptList();
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 14.48$
     * @content :对部门进行删除
     */
    @Override
    public Boolean deleteDept(Integer id) {
        Boolean flag = mapper.deleteDept(id);
        if (flag){
            redisCache.deleteObject("dept");
        }
        return flag;
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 15.20$
     * @content :对部门进行删除
     */
    @Override
    public JsDept getDeptById(Integer id) {
        return mapper.getDeptById(id);
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 15.32$
     * @content :对部门进行修改
     */
    @Override
    public Boolean updateDept(JsDept jsDept) {
        Boolean flag = mapper.updateDept(jsDept);
        if (flag){
            redisCache.deleteObject("dept");
        }
        return flag;
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 15.49$
     * @content :对部门进行修改
     */
    @Override
    public Boolean updateDeptStatus(JsDept jsDept) {
        return mapper.updateDeptStatus(jsDept);
    }
    /**
     * @author cyj
     * @date 2022.3.10$ 16.17$
     * @content :对部门进行修改
     */
    @Override
    public Boolean addDept(JsDept jsDept) {
        Boolean flag = mapper.addDept(jsDept);
        if (flag){
            redisCache.deleteObject("dept");
        }
        return flag;
    }


}
